/**
 * Created by Administrator on 2018/1/8.
 */
var obj = getSearchObj()
$(".elder-name").html(obj.elderName)
$(".elder-card-id").html(obj.elderCard)

//测试结果集
var resultModel1 = {};
var resultModel2 = {};
var resultModel3 = {};
var resultModel4 = [];
var levelResultModel = {};

//老者测试结果
var elderTestLevelRecord = null;


var resultModels = {
    "resultModel1": resultModel1,
    "resultModel2": resultModel2,
    "resultModel3": resultModel3,
    "resultModel4": resultModel4,
    "levelResultModel": levelResultModel
};

var loginedUser = getLoginedUser();

var view = {
    data: resultModels,
};

var vue_vm = new Vue({
    el: '#vue_vm',
    data: view,
    methods: {
        radioClick(item){
            // console.log(item);
            var _elderTestLevelRecord = {};
            _elderTestLevelRecord.elderId = obj.elderId;
            _elderTestLevelRecord.testTimesNumber = obj.testTimesNumber;
            _elderTestLevelRecord.staffId = loginedUser.staffId;
            _elderTestLevelRecord.testResultLevelId = item.testResultLevelId;
            _elderTestLevelRecord.level = item.level;
            _elderTestLevelRecord.levelDesc = item.levelDesc;
            _elderTestLevelRecord.createId = loginedUser.staffId;

            elderTestLevelRecord = _elderTestLevelRecord;
            console.log(_elderTestLevelRecord);
        },
    }
});

function  checkResult(){
    if (elderTestLevelRecord == null) {
        alert("请选择测试结果")
    }
    doOpenWaiting('正在提交');
    save_basic(path + '/elderTestLevelRecord/save', {"elderTestLevelRecord":elderTestLevelRecord}, function (res) {
        var elderData = obj.elderId +"&elderName=" +obj.elderName + "&elderCard=" +obj.elderCard+"&testTimesNumber="+obj.testTimesNumber;
        location.href = '2-2-1cheping-result.html?elderId=' + elderData;
    });
}
function getData() {
    getResultModel1();
    getResultModel2();
    getResultModel3();
    getResultModel4();
    getLevelResultModel();
}

getData();

function getResultModel1() {
    find_basic_by_json(path + '/elderTestResultRecord/findElderTestResult', {
        "elderId": obj.elderId,
        "testTimesNumber": Number.parseInt(obj.testTimesNumber),
        "testTopicId": 1,
    }, function (res) {
        view.data.resultModel1 = res.data[0];

    });
}

function getResultModel2() {
    find_basic_by_json(path + '/elderTestResultRecord/findElderTestResult', {
        "elderId": obj.elderId,
        "testTimesNumber": Number.parseInt(obj.testTimesNumber),
        "testTopicId": 2,
    }, function (res) {
        view.data.resultModel2 = res.data[0];
    });
}

function getResultModel3() {
    find_basic_by_json(path + '/elderTestResultRecord/findElderTestResult', {
        "elderId": obj.elderId,
        "testTimesNumber": Number.parseInt(obj.testTimesNumber),
        "testTopicId": 3,
    }, function (res) {
        view.data.resultModel3 = res.data[0];
    });
}

function getLevelResultModel() {
    find_basic_by_json(path + '/testResultLevel/findAll', {}, function (res) {
        view.data.levelResultModel = res.data;
        console.log(view.data.levelResultModel);
    });
}

function getResultModel4() {
    find_basic_by_json(path + '/elderTestDiseaseRecord/findElderTestResult', {
        "elderId": obj.elderId,
        "testTimesNumber": Number.parseInt(obj.testTimesNumber),
        "testTopicId": 4,
    }, function (res) {

        view.data.resultModel4 = res.data;
        // for(var i=0;i<res.data.length;i++){
        //     var resultItem = {};
        //     resultItem.diseaseDesc = res.data[i].diseaseDesc;
        //     var diseaseDesc = res.data[i].diseaseDesc;
        //     if(diseaseDesc.split(",").length==0){
        //         view.data.resultModel4.push(resultItem);
        //     }
        //     else {
        //         var _resultItem = {};
        //         for(var j=0;j<diseaseDesc.split(",").length;j++){
        //             _resultItem.diseaseDesc = diseaseDesc.split(",")[j].diseaseDesc
        //             view.data.resultModel4.push(_resultItem);
        //         }
        //     }
        // }
        console.log("resultModel4=" + JSON.stringify(view.data.resultModel4));
    });
}
